<template>
  <div class="cmt-container">
    <h3>发表评论</h3>
    <hr>
    <textarea placeholder="请输入要评论的内容(最多吐槽120字)" maxlength="120"></textarea>
    <mt-button type="primary" size="large">发送</mt-button>
    <div class="cmt-list">
      <div class="cmt-item" v-for="(item,i) in commentInfoList" :key="item.title">
        <div class="cmt-title">
          第{{i+1}}楼&nbsp;&nbsp; 用户：{{item.name}}&nbsp;&nbsp;发表时间：{{item.add_time}}
        </div>
        <div class="cmt-body">
          {{item.content === ''?'此用户很懒，啥也没说' : item.content}}
        </div>
      </div>
    </div>
    <mt-button class="more" type="danger" size="large" plain @click="getMoreCommentInfo()">加载更多
    </mt-button>
  </div>
</template>
<script>
export default {
  data () {
    return {
      commentInfoList: []
    }
  },
  created () {
    //console.log(this.id)
    this.getNewsCommentInfo()
  },
  methods: {
    getNewsCommentInfo () {
      this.$ajax.get('../../src/static/commentInfo.json').then((res) => {
        this.commentInfoList = res.data      //res.data可根据你的数据格式来，看需求
        //console.log(this.commentInfoList) //打印看看数据吧
      })
    },
    getMoreCommentInfo () {
      this.$ajax.get('../../src/static/commentInfo2.json').then((res) => {
        this.commentInfoList = this.commentInfoList.concat(res.data)      //res.data可根据你的数据格式来，看需求
        //console.log(this.commentInfoList) //打印看看数据吧
      })
    }
  },
  props: ["id"]
}
</script>
<style lang="scss" scoped>
.cmt-container {
  h3 {
    font-size: 18px;
  }
  textarea {
    font-size: 14px;
    height: 85px;
    margin: 0;
  }
  .cmt-list {
    margin: 5px 0;
    .cmt-item {
      font-size: 14px;
      .cmt-title {
        line-height: 35px;
        background-color: #ccc;
      }
      .cmt-body {
        line-height: 35px;
        text-indent: 2em;
      }
    }
  }
  .more {
    margin: 5px 0;
  }
}
</style>
